//
//  FocusDoctorController.m
//  quickDoctor
//
//  Created by zhaowei on 17/3/9.
//  Copyright © 2017年 SWS. All rights reserved.
//

#import "FocusDoctorController.h"
#import "focusDoctorMolde.h"
#import "focusTableViewCell.h"
#import "DoctoreIDViewController.h"

@interface FocusDoctorController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong)UITableView *tableView;

@end

static NSString *identifier = @"cell";

@implementation FocusDoctorController
{
    NSArray<focusDoctorMolde *> *_focusList;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupUI];
    [self loadData];
}

- (void)setupUI
{
    UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
    tableView.delegate = self;
    tableView.dataSource = self;
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 10)];
    [self.view addSubview:tableView];
    
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    
}
#pragma mark
#pragma mark -数据源方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return _focusList.count;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    focusTableViewCell *cell = [[focusTableViewCell alloc] init];
    
    cell.model = _focusList[indexPath.section];
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    DoctoreIDViewController *doctoreID = [[DoctoreIDViewController alloc] init];
    doctoreID.model =_focusList[indexPath.section];
    [self.navigationController pushViewController:doctoreID animated:YES];
    
}



#pragma mark
#pragma mark -加载数据
- (void)loadData
{
    NSURL *url = [[NSBundle mainBundle] URLForResource:@"focus.plist" withExtension:nil];
    
    NSArray *array = [NSArray arrayWithContentsOfURL:url];
    
    NSMutableArray *mutable = [NSMutableArray array];
    
    for (NSDictionary *dict in array) {
        
        focusDoctorMolde *model = [focusDoctorMolde focusWithDict:dict];
        
        [mutable addObject:model];
    }
    
    _focusList = mutable.copy;
}


#pragma mark
#pragma mark -设置组头组尾和行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 10;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 10;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
